package com.fractalwrench.harmonybootstrap.sample;

import static com.fractalwrench.harmonybootstrap.sample.ResourceTable.Layout_example_bootstrap_badge;

import com.beardedhen.harmonybootstrap.BootstrapBadge;
import com.beardedhen.harmonybootstrap.BootstrapButton;

import ohos.aafwk.ability.AbilitySlice;
import ohos.aafwk.content.Intent;
import ohos.agp.components.Component;
import ohos.agp.components.ComponentContainer;
import ohos.agp.components.LayoutScatter;

import java.security.SecureRandom;

public class BootstrapBadgeExample extends AbilitySlice implements Component.ClickedListener {

    private BootstrapBadge lonely_badge;
    private BootstrapButton xmlBadgeButton;
    private BootstrapButton javaBadgeButton;

    @Override
    public void onStart(Intent intent) {
        super.onStart(intent);
        ComponentContainer rootLayout = (ComponentContainer) LayoutScatter.getInstance(getContext()).parse(Layout_example_bootstrap_badge, null, false);

        lonely_badge = (BootstrapBadge) rootLayout.findComponentById(ResourceTable.Id_lonely_badge);
        xmlBadgeButton = (BootstrapButton) rootLayout.findComponentById(ResourceTable.Id_xml_badge_button);
        javaBadgeButton = (BootstrapButton) rootLayout.findComponentById(ResourceTable.Id_java_badge_button);

        BootstrapBadge badgeThird = new BootstrapBadge(this);
        badgeThird.setBadgeText("Hi!");
        javaBadgeButton.setBadge(badgeThird);


        lonely_badge.setClickedListener(this);
        xmlBadgeButton.setClickedListener(this);
        javaBadgeButton.setClickedListener(this);

        super.setUIContent(rootLayout);
    }

    @Override
    public void onClick(Component component) {
        switch (component.getId()) {
            case ResourceTable.Id_lonely_badge:
                lonely_badge.setBadgeText(String.valueOf(new SecureRandom().nextInt()));
                break;
            case ResourceTable.Id_xml_badge_button:
                xmlBadgeButton.setBadgeText(String.valueOf(new SecureRandom().nextInt()));
                break;
            case ResourceTable.Id_java_badge_button:
                javaBadgeButton.setBadgeText(String.valueOf(new SecureRandom().nextInt()));
                break;
            default:
                break;
        }
    }
}
